package com.tanguy.user.ui.me.adapter

import android.view.View
import com.tanguy.user.R
import com.tanguy.user.base.JustAdapter
import com.tanguy.user.bean.CouponsBean
import cn.sinata.xldutils_kotlin.utils.SpanBuilder
import com.tanguy.user.utlis.TimeUtils
import com.tanguy.user.utlis.extend.getColorKt
import com.tanguy.user.utlis.extend.setBackground
import com.tanguy.user.utlis.extend.setText
import com.tanguy.user.utlis.extend.toTimeString
import java.util.*

/**
 * Created by dab on 2017/10/10 0010 14:01
 */
class CouponsAdapter(data: ArrayList<CouponsBean>) : JustAdapter<CouponsBean>(data, R.layout.item_coupons) {
    override fun bind(itemView: View, data: CouponsBean, position: Int) {
        val money = SpanBuilder("￥${data.money}").size(1, 2, 13).build().toString()
        var moneyColor = R.color.color_fb408e
        if (data.state != 1) {
            moneyColor = R.color.color_999999
        }
        itemView.apply {
            setText(R.id.tv_money, money).setTextColor(context.getColorKt(moneyColor))
            setText(R.id.tv_type, data.typeString)
            setText(R.id.tv_purpose, data.purpose)
            setText(R.id.tv_time, "有效期至${data.endtime.toTimeString(TimeUtils.TIME_YYYY_MM_DD)}")
            setBackground(R.id.tv_icon, data.icon)
            setBackground(R.id.view_background, data.viewBackground())

        }
    }

}